<template>
    <div class="app-container">
        <el-table v-loading="loading" :data="goodsList">
            <el-table-column label="商品照片" align="center">
                <template slot-scope="scope">
                    <el-image style="width: 100px; height: 100px" :src="scope.row.goodImg" fit="fill"></el-image>
                </template>
            </el-table-column>
            <el-table-column label="商品名称" align="center" prop="goodName" />
            <el-table-column label="商品进价" align="center">
                <template slot-scope="scope">
                    <span>{{ scope.row.purchPrice }}元</span>
                </template>
            </el-table-column>
            <el-table-column label="购买数量" align="center" prop="num" />
            <el-table-column label="商品类别" align="center" prop="typeId">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.goods_type" :value="scope.row.typeId" />
                </template>
            </el-table-column>
            <el-table-column label="总价" align="center" prop="allPrice">
                <template slot-scope="scope">
                    <span>{{ scope.row.allPrice }}元</span>
                </template>
            </el-table-column>
        </el-table>
        订单总价: {{ a_AllPrice }}元
    </div>
</template>

<script>
import { getPurchasedetails } from "@/api/system/purchasedetails"
export default {
    name: "purchaseData",
    dicts: ['goods_type'],
    data() {
        return {
            goodsList: [],
            loading: true,
            a_AllPrice: 0,   // 订单总价
        }
    },
    created() {
        const purchaseID = this.$route.params && this.$route.params.purchaseID;
        this.getList(purchaseID);
    },
    methods: {
        getList(purchaseID) {
            var that = this;
            getPurchasedetails(purchaseID).then(
                (resp) => {
                    if (resp.code == 200) {
                        for (var i = 0; i < resp.data.length; i++) {
                            resp.data[i].allPrice = resp.data[i].purchPrice * resp.data[i].num;
                            that.a_AllPrice += resp.data[i].allPrice;
                        }
                        that.goodsList = resp.data;
                        that.loading = false;
                    }
                }
            );

        }
    }
}
</script>

<style></style>